<template>
  <div class="dashboard">
    <div class="stats-grid">
      <div class="stat-card" @mouseenter="handleHover" @mouseleave="handleLeave">
        <div class="stat-icon users-icon">
          <i class="fas fa-users"></i>
        </div>
        <div class="stat-content">
          <h3>总用户数</h3>
          <div class="stat-number">1,234</div>
          <div class="stat-change positive">+12%</div>
        </div>
      </div>
      <div class="stat-card" @mouseenter="handleHover" @mouseleave="handleLeave">
        <div class="stat-icon visits-icon">
          <i class="fas fa-eye"></i>
        </div>
        <div class="stat-content">
          <h3>今日访问</h3>
          <div class="stat-number">567</div>
          <div class="stat-change positive">+8%</div>
        </div>
      </div>
      <div class="stat-card" @mouseenter="handleHover" @mouseleave="handleLeave">
        <div class="stat-icon orders-icon">
          <i class="fas fa-shopping-cart"></i>
        </div>
        <div class="stat-content">
          <h3>订单数量</h3>
          <div class="stat-number">89</div>
          <div class="stat-change negative">-3%</div>
        </div>
      </div>
      <div class="stat-card" @mouseenter="handleHover" @mouseleave="handleLeave">
        <div class="stat-icon revenue-icon">
          <i class="fas fa-dollar-sign"></i>
        </div>
        <div class="stat-content">
          <h3>收入</h3>
          <div class="stat-number">¥12,345</div>
          <div class="stat-change positive">+15%</div>
        </div>
      </div>
    </div>

    <div class="recent-activity card">
      <h3>最近活动</h3>
      <div class="activity-container">
        <div class="activity-list" :style="{ transform: `translateY(${scrollOffset}px)` }">
          <div class="activity-item" v-for="activity in activities" :key="activity.id">
            <div class="activity-time">{{ activity.time }}</div>
            <div class="activity-content">{{ activity.content }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Dashboard',
  data() {
    return {
      scrollOffset: 0,
      activities: [
        { id: 1, time: '10:30', content: '新用户注册：张三' },
        { id: 2, time: '09:15', content: '订单完成：订单 #12345' },
        { id: 3, time: '08:45', content: '系统更新完成' },
        { id: 4, time: '08:30', content: '商品库存不足预警：iPhone 15 Pro' },
        { id: 5, time: '08:15', content: '新订单创建：订单 #12346' },
        { id: 6, time: '08:00', content: '用户登录：李四' },
        { id: 7, time: '07:45', content: '库存调整：MacBook Air M2 +5' },
        { id: 8, time: '07:30', content: '支付成功：订单 #12344' },
        { id: 9, time: '07:15', content: '商品上架：Nike运动鞋' },
        { id: 10, time: '07:00', content: '系统备份完成' }
      ]
    }
  },
  mounted() {
    this.startScroll()
  },
  beforeUnmount() {
    this.stopScroll()
  },
  methods: {
    handleHover(event) {
      const card = event.currentTarget
      card.style.transform = 'translateY(-5px) scale(1.02)'
      card.style.boxShadow = '0 8px 25px rgba(0, 0, 0, 0.15)'
    },
    handleLeave(event) {
      const card = event.currentTarget
      card.style.transform = 'translateY(0) scale(1)'
      card.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.1)'
    },
    startScroll() {
      this.scrollInterval = setInterval(() => {
        this.scrollOffset -= 1
        if (this.scrollOffset <= -this.activities.length * 60) {
          this.scrollOffset = 0
        }
      }, 50)
    },
    stopScroll() {
      if (this.scrollInterval) {
        clearInterval(this.scrollInterval)
      }
    }
  }
}
</script>

<style scoped>
.dashboard {
  max-width: 1200px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 25px;
  margin-bottom: 30px;
}

.stat-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 25px;
  border-radius: 15px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.stat-card:hover::before {
  opacity: 1;
}

.stat-card:nth-child(1) {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.stat-card:nth-child(2) {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.stat-card:nth-child(3) {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.stat-card:nth-child(4) {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.stat-card {
  display: flex;
  align-items: center;
  color: white;
}

.stat-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 20px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
}

.stat-icon i {
  font-size: 24px;
  color: white;
}

.stat-content {
  flex: 1;
}

.stat-content h3 {
  margin: 0 0 8px 0;
  font-size: 14px;
  font-weight: 500;
  opacity: 0.9;
}

.stat-number {
  font-size: 32px;
  font-weight: bold;
  margin-bottom: 5px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stat-change {
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
}

.stat-change.positive {
  color: #a8f5a8;
}

.stat-change.negative {
  color: #ffb3b3;
}

.recent-activity {
  background: white;
  border-radius: 15px;
  padding: 25px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.recent-activity h3 {
  margin-bottom: 20px;
  color: #2c3e50;
  font-size: 18px;
  font-weight: 600;
}

.activity-container {
  height: 200px;
  overflow: hidden;
  position: relative;
}

.activity-list {
  transition: transform 0.5s ease;
}

.activity-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #f0f0f0;
  transition: all 0.3s ease;
}

.activity-item:hover {
  background: #f8f9fa;
  padding-left: 10px;
  border-radius: 8px;
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-time {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  margin-right: 15px;
  min-width: 60px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.activity-content {
  color: #2c3e50;
  flex: 1;
  font-size: 14px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .stat-card {
    padding: 20px;
  }
  
  .stat-icon {
    width: 50px;
    height: 50px;
    margin-right: 15px;
  }
  
  .stat-number {
    font-size: 28px;
  }
}
</style> 